<template>
	<div>
		<!-- <mt-header :title="headerTitle">
        <router-link to="" slot="left">
          <mt-button    @click="$router.back(-1)">取消</mt-button>
        </router-link>
        <mt-button slot="right" v-on:click="UpdateUserName">完成</mt-button>
    	</mt-header> -->
        <setHeader :title="headerTitle" settext="保存" @done="UpdateUserName()"></setHeader>
        <div class="pagecontent">
			<mt-field  placeholder="请输入名称" :attr="{ maxlength: 11 }" v-model="update_arr.mobile"></mt-field>
        </div>
		<so-footer></so-footer>
	</div>
</template>
<script>
import setHeader from '../public/setHeader.vue';
import soFooter from '../public/nav.vue';
import { MessageBox } from 'mint-ui';
import qs from 'qs';

export default {

	data() {
      return {
        email: '',
        userInfo:'',
        headerTitle:'电话号码',
        update_arr:{
            username:'',
            access_token:'',
        },
      };
    },
    components: {
		setHeader,
		soFooter
	},
		created() {
				let that = this;
				that.userInfo = window.localStorage.getItem('userInfo');
				that.userInfo = JSON.parse(that.userInfo);
				that.update_arr.username = that.userInfo.username;
		},
    mounted() {
    // 	let that = this;
    // 	var a = Promise.resolve(this.getUserInfo())
		// a.then(
		// 	function (result) { 
    //         console.log(result);
		// 	that.userInfo = result;
    //         that.update_arr.username = result.username;
		// })

      // console.log(that.userInfo);

    },
    methods:{
    	NextStep:function(){
    		
    		let that = this;
    		let uid = that.userInfo.id;
    		let circlename = this.circlename;
    		if(circlename == '' || circlename == undefined){
    			MessageBox('温馨提示', '请输入圈子名称');
    		}else{
    			this.$post(
                that.$path+'/api.php/company/getUserAllCompanyList',{userId:uid})
                .then((res) => {
	               let count = res.count;
		            if(count < 1){
		                MessageBox.alert('您需要先绑定企业').then(action => {
		                	this.$router.push({path: '/companyCreate'}); 
		                });
		            }else{
		                this.$post(
		                  that.$path+'/api.php/Circle/checkCircleName',{c_name:circlename})
		                .then((res) => {
		                  if(res.code == 200){
		                  	this.$router.push({path: '/incircle', query: {paicheNo: res.data.cid}}); 
		     //              	MessageBox.confirm('此圈子名称已被创建 请换一个名称 或加入此圈').then(action => {
		     //                  this.$router.push({path: '/userCenter/circleindex', query: {paicheNo: res.data.cid}}); 
							// });
		                  }else if(res.code == 202){
		                  	//新创建圈子
		                  	this.$router.push({path: '/createNewCircle', query: {circlename: circlename}}); 

		                  }
		                })
		            }

          		})
    			
    			
    		}
    		
    	},
        UpdateUserName:function(){ 
            let that = this;
            let access_token = window.localStorage.getItem('access_token');
            that.update_arr.access_token = access_token;
            console.log(access_token);
            // alert(access_token);
            if(that.update_arr.username){ 
                that.$post(that.$path+'/index.php/api/username',that.update_arr).then((response) => { 
                        console.log(response);
                        if(response.code == 200){ 
                             that.$router.push({path:'/userUpdate'});
                        }
                })
               
            }

        }
    }
}

</script>

<style >
.el-long-create-button{
	margin-top:50px;
}
</style>